package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.AdmissionForm;
import com.woniuxy.entity.DischargeForm;
import com.woniuxy.entity.dto.DisChargeDTO;
import com.woniuxy.mapper.DischargeFormMapper;
import com.woniuxy.mapper.InHospitalMapper;
import com.woniuxy.service.DischargeFormService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DischargeFormServiceImpl implements DischargeFormService, SaasService {
    @Autowired
    DischargeFormMapper formMapper;

    @Autowired
    InHospitalMapper inHospitalMapper;
    @Override
    public ResponseData<?> queryList(PageParam<DisChargeDTO> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        List<DischargeForm> dischargeForms = formMapper.queryList(pageParam.getParam());
        PageInfo pageInfo = new PageInfo(dischargeForms);
        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData<?> updateHzAndOaDate(DisChargeDTO disChargeDTO) {
        disChargeDTO.setOaStatus("2");
        formMapper.updateOaStatus(disChargeDTO);
        disChargeDTO.setHzStatus("1");
        inHospitalMapper.updateHzDate(disChargeDTO);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> addDischarge(DischargeForm dischargeForm) {
        formMapper.addDischarge(dischargeForm);
        return new ResponseData<>().ok();
    }


}
